<%--
  Created by IntelliJ IDEA.
  User: Rain
  Date: 2018/9/6
  Time: 14:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>信息管理系统</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <script type="text/javascript" src="/htdc/scripts/jquery/jquery-1.7.1.js"></script>
    <link href="/htdc/style/authority/basic_layout.css" rel="stylesheet" type="text/css">
    <link href="/htdc/style/authority/common_style.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="/htdc/scripts/authority/commonAll.js"></script>
    <script type="text/javascript" src="/htdc/scripts/jquery/jquery-1.4.4.min.js"></script>
    <script src="/htdc/scripts/My97DatePicker/WdatePicker.js" type="text/javascript" defer="defer"></script>
    <script type="text/javascript" src="/htdc/scripts/artDialog/artDialog.js?skin=default"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            /*
             * 提交
             */
            $("#submitbutton").click(function () {

                var data = $('#submitForm').serialize();
                if (validateForm()) {
                    // checkFyFhSubmit();
                    $.ajax({
                        type: "POST",
                        url: "/htdc/room/addRoom",
                        data: data,
                        success: function (result) {
                            if (result == 'success') {
                                /**  关闭弹出iframe  **/
                                window.parent.$.fancybox.close();
                            }
                        }

                    })


                    $("#submitbutton").submit(); //提交

                    // parent.$.fancybox.close(); //关闭
                    //
                    // parent.window.location.reload(); //刷新父窗口

                }
            });

            /*
             * 取消
             */
            $("#cancelbutton").click(function () {
                /**  关闭弹出iframe  **/
                window.parent.$.fancybox.close();
            });

            var result = 'null';
            if (result == 'success') {
                /**  关闭弹出iframe  **/
                window.parent.$.fancybox.close();
            }
        });

        /** 检测房源房号是否存在  **/
        function checkFyFh() {
            // 分别获取小区编号、栋号、层号、房号
            var fyID = $('#fyID').val();
            var fyXqCode = $("#fyXq").val();
            var fyDh = $("#fyDh").val();
            var fyCh = $("#fyCh").val();
            var fyFh = $("#fyFh").val();
            if (fyXqCode != "" && fyDh != "" && fyCh != "" && fyFh != "") {
                // 给房屋坐落地址赋值
                $("#fyZldz").val($('#fyDh option:selected').text() + fyCh + "-" + fyFh);
                // 异步判断该房室是否存在，如果已存在，给用户已提示哦
                $.ajax({
                    type: "POST",
                    url: "/htdc/room/changeRoom",
                    data: {
                        "fangyuanEntity.fyID": fyID,
                        "fangyuanEntity.fyXqCode": fyXqCode,
                        "fangyuanEntity.fyDhCode": fyDh,
                        "fangyuanEntity.fyCh": fyCh,
                        "fangyuanEntity.fyFh": fyFh
                    },
                    dataType: "text",
                    success: function (data) {
// 					alert(data);
                        // 如果返回数据不为空，更改“房源信息”
                        if (data == "1") {
                            art.dialog({
                                icon: 'error',
                                title: '友情提示',
                                drag: false,
                                resize: false,
                                content: '该房室在系统中已经存在哦，\n请维护其他房室数据',
                                ok: true,
                            });
                            $("#fyFh").css("background", "#EEE");
                            $("#fyFh").focus();
                            return false;
                        }
                    }
                });
            }
        }

    
        /** 表单验证  **/
        function validateForm() {

            if ($("#roomArea").val() == "") {
                art.dialog({icon: 'error', title: '友情提示', drag: false, resize: false, content: '填写房源产权面积', ok: true,});
                return false;
            }
            if ($("#roomRealArea").val() == "") {
                art.dialog({icon: 'error', title: '友情提示', drag: false, resize: false, content: '填写可出租面积', ok: true,});
                return false;
            }
            if ($("#rname").val() == "") {
                art.dialog({icon: 'error', title: '友情提示', drag: false, resize: false, content: '填写房源名称', ok: true,});
                return false;
            }
            return true;
        }
    </script>
</head>
<body>
<form id="submitForm" name="submitForm" action="/htdc/room/addRoom" method="post">
    <div id="container">
        <div id="nav_links">
            当前位置：基础数据&nbsp;>&nbsp;<span style="color: #1A5CC6;">房源编辑</span>
            <div id="page_close">
                <a href="javascript:parent.$.fancybox.close();">
                    <img src="/htdc/images/common/page_close.png" width="20" height="20"
                         style="vertical-align: text-top;"/>
                </a>
            </div>
        </div>
        <div class="ui_content">
            <table class="table" cellspacing="0" cellpadding="0" width="100%" align="center" border="0">

                <tr>
                    <th>合同编号</th>
                    <th>租期</th>
                    <th>租金收益</th>
                    <th>单价</th>
                </tr>

                <c:forEach items="${agreements}" var="agreement">
                    <tr>
                        <td>${agreement.aid}</td>
                        <td>${agreement.rentTime}--${agreement.rentEnd}</td>
                        <td>${agreement.realRentMoney}</td>
                        <td>${agreement.price},递增率:${agreement.growthRate}</td>
                    </tr>
                </c:forEach>


            </table>
        </div>
    </div>
</form>

</body>
</html>